package com.liucxu.qiushimeinv.Presenter.Impl;

import com.liucxu.qiushimeinv.Model.Bean.BaseBean;
import com.liucxu.qiushimeinv.Model.Bean.GirlsBean;
import com.liucxu.qiushimeinv.Model.IGirlsModel;
import com.liucxu.qiushimeinv.Model.Impl.GirlsModelImpl;
import com.liucxu.qiushimeinv.Presenter.IGirlsPresenter;
import com.liucxu.qiushimeinv.Utils.CommonSubscriber;
import com.liucxu.qiushimeinv.Utils.TransformUtils;
import com.liucxu.qiushimeinv.View.IView.IGirlsListView;

/**
 * 获取美女列表的presenter实现类
 * Created by liukanshan on 2017/1/1.
 */

public class GirlsPresenterImpl implements IGirlsPresenter {

    private IGirlsModel model;
    private IGirlsListView view;


    public GirlsPresenterImpl(IGirlsListView mView) {
        if (mView != null) {
            view = mView;
            model = new GirlsModelImpl();
        }
    }

    @Override
    public void getGirls(String pageNum) {
        view.showLoading();
        model.getGirls(pageNum).compose(TransformUtils.<GirlsBean>defaultScheduler()).subscribe(new CommonSubscriber<GirlsBean>() {
            @Override
            public void onSuccess(GirlsBean response) {
                view.hideLoading();
                view.setGirls(response);
            }

            @Override
            public void onFailure(BaseBean response) {
                view.hideLoading();
                view.showError(response);
            }
        });
    }
}
